<template>
  <div>
    <el-table
      v-if="visible"
      :data="goodsList"
      highlight-current-row
      :rules="rules"
    >
      <el-table-column label="状态" width="100px">
        <template slot-scope="{ row }"
          ><el-tag v-if="row.type === 1">项目</el-tag>
          <el-tag v-else type="success">物料</el-tag></template
        >
      </el-table-column>
      <el-table-column label="识别码" prop="goodsFullCode" width="150px" />
      <el-table-column label="货品简称" prop="goodsAbbr" width="150" />

      <el-table-column label="货号" prop="goodsCode" width="150" />
      <el-table-column label="批号" width="150">
        <template slot-scope="{ row }">
          <el-input v-model="row.goodsBatchCode" :disabled="true" />
        </template>
      </el-table-column>
      <el-table-column label="单位" width="100">
        <template slot-scope="{ row }">
          <span v-if="row.unit">
            {{ row.unit }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="单位用量" width="150">
        <template slot-scope="{ row }">
          <span v-if="row.bomUnit">
            {{ row.bomUnit }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="计划数量" width="120">
        <template slot-scope="{ row }">
          <el-input v-model="row.expectQuantity" :disabled="true" />
        </template>
      </el-table-column>
      <el-table-column label="实际数量" width="120">
        <template slot-scope="{ row }">
          <el-input
            v-model="row.factQuantity"
            :disabled="currentStatus || false"
            type="number"
          />
        </template>
      </el-table-column>
      <!-- <el-table-column label="规格" width="100">
        <template slot-scope="{ row }">
          <el-input v-model="row.specification" :disabled="true" />
        </template>
      </el-table-column> -->
      <el-table-column label="浓度" width="100">
        <template slot-scope="{ row }">
          <el-input v-model="row.factCount" :disabled="true" />
        </template>
      </el-table-column>
      <el-table-column v-if="currentStatus" width="120px" label="操作">
        <template slot-scope="{ row }">
          <el-tooltip effect="dark" content="复核" placement="top-start">
            <el-checkbox
              v-model="row.checkFlag"
              :disabled="row.checkFlag"
              @change="checkboxChange(row)"
              >确认</el-checkbox
            >
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { updateTaskLog, saveCheckEquipment } from '@/api/mes/manufactureTask.js'
export default {
  props: {
    visible: {
      required: true,
      type: Boolean
    },
    goodsList: {
      required: true,
      type: Array,
      default: null
    },
    currentTask: {
      type: Object,
      default: null
    },
    currentStatus: {
      type: Boolean,
      required: false
    }
  },
  data() {
    return {
      rules: {}
      // goodsList: null
    }
  },
  watch: {
    currentTask: {
      handler(data) {
        console.log(this.goodsList, '3888888888')
        const row = {
          manufactureTaskId: this.currentTask.manufactureTaskId,
          goodsList: this.goodsList
        }
        if (row.goodsList && row.goodsList.length > 0) {
          updateTaskLog(row).then((res) => {})
        }
      },
      deep: true
    }
  },
  methods: {
    checkboxChange(row) {
      if (!row.factQuantity) {
        this.$message.warning('未填入实际数量')
        row.checkFlag = false
        return
      } else {
      this.materialGoodsList.forEach((e) => {
        if (
          e.goodsCode === row.goodsCode &&
          e.specification === row.specification
        ) {
          if (!e.checkFlag) {
            e.checkFlag = true
          } else {
            return
          }
        } else {
          if (e.checkFlag) {
            e.checkFlag = true
          } else {
            e.checkFlag = false
          }
        }
      })
      const data = {
        manufactureTaskCode: this.currentTask.manufactureTaskCode,
        manufactureTaskId: this.currentTask.manufactureTaskId,
        goodsList: this.materialGoodsList
      }
      saveCheckEquipment(data).then((res) => {
        console.log(res, 'dhdhdhdh')
      })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>

